package com.yrot;

import com.yrot.admin.entity.SysExpert;
import com.yrot.common.annotation.SysLog;
import org.apache.shiro.SecurityUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;

@SpringBootApplication
@RequestMapping
@MapperScan("com.yrot.*.mapper")
@EnableCaching
@EnableScheduling
public class ExamTrainApplication {

	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(ExamTrainApplication.class);
		app.addListeners(new ApplicationPidFileWriter());
		app.run(args);
	}

	@RequestMapping(value = {"/","/index"})
	@SysLog("登录系统")
	public ModelAndView index(ModelAndView modelAndView){
		SysExpert user = (SysExpert) SecurityUtils.getSubject().getPrincipal();
		modelAndView.addObject("userName",user.getExpertName());
		if(user!=null && user.getRoleName().equals("ADMIN")){
			modelAndView.setViewName("admin");
			return modelAndView;
		}
		modelAndView.setViewName("index");
		return modelAndView;
	}

	@RequestMapping("/admin")
	public String admin(){
		return "admin";
	}

	@GetMapping("/login")
	public String login(){
		return "login";
	}

}
